package com.example.springbott.controller;

import com.example.springbott.aspactJ.OperationName;
import com.example.springbott.bean.*;
import com.example.springbott.bean.common.CommonData;
import com.example.springbott.bean.common.PageInfoBase;
import com.example.springbott.service.AdminUserService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestControllerAdvice
@RequestMapping("admin")
public class AdminUserController {
    @Autowired
    AdminUserService adminService;


    //--------------------------------------------------Kerbal--------------------------------------------------

    /**
     * 管理用户列表
     * Note:这个url的参数含有userId，但是userId对应的是另一个get请求，并且根据UserId的查询其他条件是没有意义的；
     * //http://localhost:8083/admin/user/list?page=1&limit=20&username=123&mobile=123&userId=&sort=add_time&order=desc
     *
     * @param page  页面
     * @param limit 限制
     * @param sort  排序
     * @param order 订单
     * @return {@link BaseRespVo}
     */
    @RequiresPermissions("admin:user:list")
    @RequestMapping("user/list")
    @OperationName("1")
    public BaseRespVo adminUserList(Integer page, Integer limit, String sort, String order, String username, Integer mobile) {
        CommonData<MarketUser> marketUserCommonData = adminService.adminUserList(page, limit, sort, order, username, mobile);
        BaseRespVo ok = BaseRespVo.ok(marketUserCommonData);
        return ok;
    }


    /**
     * 管理用户细节
     * http://localhost:8083/admin/user/detail?id=1
     *
     * @param id id
     * @return {@link BaseRespVo}
     */
    @RequiresPermissions("admin:user:list")
    @RequestMapping("user/detail")
    @OperationName("1")
    public BaseRespVo adminUserDetail(Integer id) {
        return BaseRespVo.ok(adminService.adminUserDetail(id));
    }


    /**
     * 管理用户更新
     * http://localhost:8083/admin/user/update
     *
     * @return {@link BaseRespVo}
     */
    @RequiresPermissions("admin:user:list")
    @RequestMapping("user/update")
    @OperationName("1")
    public BaseRespVo adminUserUpdate(@RequestBody MarketUser user) {
        int code = adminService.adminUserUpdate(user);
        if (code == 1) {
            BaseRespVo ok = BaseRespVo.ok(null);
            ok.setErrmsg("成功");
            return ok;
        } else {
            return BaseRespVo.invalidData("修改失败");
        }
    }


    /**
     * 管理地址列表
     * http://182.92.235.201:8083/admin/address/list?page=1&limit=20&name=name&userId=1&sort=add_time&order=desc
     * 目前返回值会有问题，因为数据库表中没有对应的数据
     *
     * @return {@link BaseRespVo}
     */
    @RequiresPermissions("admin:address:list")
    @RequestMapping("address/list")
    @OperationName("1")
    public BaseRespVo adminAddressList(PageInfoBase pageInfoBase, String name, Integer userId) {

        CommonData<MarketAddress> marketAddressCommonData = adminService.adminAddressList(pageInfoBase, name, userId);
        return BaseRespVo.ok(marketAddressCommonData);
    }


    /**
     * 管理员收集名单
     * http://localhost:8083/admin/collect/list?page=1&limit=20&userId=1&valueId=12&sort=add_time&order=desc
     *
     * @param pageInfoBase 页面信息基础
     * @param userId       用户id
     * @param valueId      id值
     * @return {@link BaseRespVo}
     * 问题说明：原始页面无返回数据，
     * @KERBAL
     */
    @RequiresPermissions("admin:collect:list")
    @RequestMapping("collect/list")
    @OperationName("1")
    public BaseRespVo adminCollectList(PageInfoBase pageInfoBase, Integer userId, Integer valueId) {
        adminService.adminCollectList(pageInfoBase,userId,valueId);


        return BaseRespVo.ok(new CommonData<>());
    }


    /**
     * 管理脚印列表
     * http://182.92.235.201:8083/admin/footprint/list?page=1&limit=20&userId=1&goodsId=12&sort=add_time&order=desc
     *
     * @param pageInfoBase 页面信息基础
     * @param UserId       用户id
     * @param goodsId      商品id
     * @return {@link BaseRespVo}
     * @kerbal
     */
    @RequiresPermissions("admin:footprint:list")
    @RequestMapping("footprint/list")
    @OperationName("1")
    public BaseRespVo adminFootPrintList(PageInfoBase pageInfoBase, Integer UserId, Integer goodsId) {
        CommonData<MarketFootprint> marketFootprintCommonData = adminService.adminFootPrintList(pageInfoBase, UserId, goodsId);
        return BaseRespVo.ok(marketFootprintCommonData);


    }
    /**
     * @Author 付常莹
     * @param page
     * @param limit
     * @param keyword
     * @param sort
     * @param order
     * @return
     * 该方法用于用户管理模块，搜索，展示用户搜素记录
     */
    @GetMapping("history/list")
    @OperationName("1")
    public BaseRespVo historyList(Integer page,Integer limit,String keyword,String sort ,String order,Integer userId){
        CommonData<MarketSearchHistory> data = adminService.historyList(page,limit,keyword,sort,order,userId);
        return BaseRespVo.ok(data);
    }

//--------------------------------------------------Kerbal--------------------------------------------------


    /**
     * @Author 付常莹
     * @param page
     * @param limit
     * @param username 用户名
     * @param sort
     * @param order
     * @param id 反馈id
     * @return
     * 该方法用于搜索展示用户的反馈
     */
    @GetMapping("feedback/list")
    @OperationName("1")
    public BaseRespVo feedbackList(Integer page,Integer limit,String username,String sort,String order,Integer id){
        CommonData<MarketFeedback> data = adminService.feedbackList(page,limit,username,sort,order,id);
        return BaseRespVo.ok(data);
    }

}
